package com.example.myapplication;

/**
 * K线数据模型类
 */
public class KLineData {
    private float open;      // 开盘价
    private float close;     // 收盘价
    private float high;      // 最高价
    private float low;       // 最低价
    private long volume;     // 成交量
    private String date;     // 日期
    private long timestamp;  // 时间戳

    public KLineData(float open, float close, float high, float low, long volume, String date) {
        this.open = open;
        this.close = close;
        this.high = high;
        this.low = low;
        this.volume = volume;
        this.date = date;
        this.timestamp = System.currentTimeMillis();
    }

    public KLineData(float open, float close, float high, float low, long volume, String date, long timestamp) {
        this.open = open;
        this.close = close;
        this.high = high;
        this.low = low;
        this.volume = volume;
        this.date = date;
        this.timestamp = timestamp;
    }

    // Getter methods
    public float getOpen() {
        return open;
    }

    public float getClose() {
        return close;
    }

    public float getHigh() {
        return high;
    }

    public float getLow() {
        return low;
    }

    public long getVolume() {
        return volume;
    }

    public String getDate() {
        return date;
    }

    public long getTimestamp() {
        return timestamp;
    }

    // Setter methods
    public void setOpen(float open) {
        this.open = open;
    }

    public void setClose(float close) {
        this.close = close;
    }

    public void setHigh(float high) {
        this.high = high;
    }

    public void setLow(float low) {
        this.low = low;
    }

    public void setVolume(long volume) {
        this.volume = volume;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    /**
     * 判断是否为阳线（收盘价 > 开盘价）
     */
    public boolean isRising() {
        return close > open;
    }

    /**
     * 获取实体部分的高度
     */
    public float getBodyHeight() {
        return Math.abs(close - open);
    }

    /**
     * 获取上影线长度
     */
    public float getUpperShadowLength() {
        return high - Math.max(open, close);
    }

    /**
     * 获取下影线长度
     */
    public float getLowerShadowLength() {
        return Math.min(open, close) - low;
    }

    @Override
    public String toString() {
        return "KLineData{" +
                "date='" + date + '\'' +
                ", open=" + open +
                ", close=" + close +
                ", high=" + high +
                ", low=" + low +
                ", volume=" + volume +
                '}';
    }
}